package com.project.${pkgname}.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.project.${pkgname}.dto.${dtoName};
import com.project.${pkgname}.dto.${searchDtoName};
import com.project.${pkgname}.domain.service.${className}Service;
import com.project.common.domain.BizPage;
import com.project.common.domain.Result;
import com.project.common.domain.datascope.DataScope;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author: ${createName}
 * @blame: ${name}API
 * @date: ${time}
 **/
@Tag(name = "${name}接口")
@RestController
@RequestMapping("/${pkgname}/${baseName}/")
public class ${className}Controller {
    @Resource
    private ${className}Service ${className?uncap_first}Service;

    @Operation(summary = "${name}分页列表")
    @GetMapping("findPage")
    @DataScope
    public Result<BizPage<${dtoName}>> findPage(${searchDtoName} searchDTO, @PageableDefault(sort = {"id"}, direction = Sort.Direction.DESC) Pageable pageable) {
        BizPage<${dtoName}> page = ${className?uncap_first}Service.findPage(searchDTO,pageable);
        return Result.success(page);
    }

    @Operation(summary = "${name}详细")
    @GetMapping("detail/{id}")
    public Result<${dtoName}> findById(@PathVariable("id") Long id) {
        return ${className?uncap_first}Service.findById(id);
    }

    @Operation(summary = "${name}保存/更新")
    @PostMapping("save")
    public Result<${dtoName}> save(@RequestBody ${dtoName} ${dtoName?uncap_first}) {
        return ${className?uncap_first}Service.save(${dtoName?uncap_first});
    }

    @Operation(summary = "${name}删除")
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return ${className?uncap_first}Service.delete(id, StpUtil.getLoginIdAsLong());
    }
}